﻿<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="Shortcut Icon" href="../images/aecc.ico" type="image/x-icon" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="../StaticFiles/element-ui/element-ui.css">
  <link rel="stylesheet" href="../StaticFiles/nprogress/nprogress.min.css">
  <link rel="stylesheet" href="../styles/vue-page-common.css">
  <script src="../Scripts/vue.min.js"></script>
  <script src="../StaticFiles/element-ui/element-ui.js"></script>
  <script src="../Scripts/axios.min.js"></script>
  <script src="../StaticFiles/nprogress/nprogress.min.js"></script>
  <script src="../Scripts/dayjs.min.js"></script>
  <script src="../Scripts/axios.config.js"></script>
  <title>问题上报查询报表</title>
</head>

<body>
  <div id="app" v-cloak v-on:keyup.enter="getData">
    <!-- 报表标题 -->
    <vue2-report-header :title="'问题上报查询报表'"></vue2-report-header>
    <div style="padding:10px;">
      <!-- 查询条件区 -->
      <el-form :inline="true" :model="queryInfo" ref="queryInfoRef" :rules="rules" :label-position="'left'">
        <el-form-item label="分厂:" prop="factoryid">
          <el-select v-model="queryInfo.factoryid" placeholder="请选择分厂" clearable filterable
            @change="bindSearchWorkcenter" :disabled="ddlFactoryDisabled">
            <el-option v-for="f in factoryList" :key="f.factoryid" :label="f.factoryname" :value="f.factoryid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="提出工区">
          <el-select v-model="queryInfo.createWorkcenterid" placeholder="请选择工区" clearable filterable>
            <el-option v-for="w in workcenterList" :key="w.workcenterid" :label="w.workcentername"
              :value="w.workcenterid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="提出人:">
          <el-input v-model.trim="queryInfo.creatPerson" placeholder="请输入提出人" clearable></el-input>
        </el-form-item>

        <el-form-item label="提出时间:">
          <el-date-picker v-model="queryInfo.createDate" type="daterange" range-separator="至" value-format="yyyy-MM-dd"
            start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"></el-date-picker>
        </el-form-item>

        <el-form-item label="状态:">
          <el-select v-model="queryInfo.status" placeholder="请选择处理状态" clearable filterable>
            <el-option :key="'未处理'" :label="'未处理'" :value="'未处理'">
            </el-option>
            <el-option :key="'处理中'" :label="'处理中'" :value="'处理中'">
            </el-option>
            <el-option :key="'处理完'" :label="'处理完'" :value="'处理完'">
            </el-option>
            <el-option :key="'已关闭'" :label="'已关闭'" :value="'已关闭'">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="责任工区">
          <el-select v-model="queryInfo.resWorkcenterid" placeholder="请选择工区" clearable filterable>
            <el-option v-for="w in workcenterList" :key="w.workcenterid" :label="w.workcentername"
              :value="w.workcenterid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="责任人:">
          <el-input v-model.trim="queryInfo.responsePerson" placeholder="请输入责任人" clearable></el-input>
        </el-form-item>

        <el-form-item label="流水卡号:">
          <el-input v-model.trim="queryInfo.containername" placeholder="请输入流水卡号" clearable></el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="small" @click="getData" :disabled="disabled">查询
          </el-button>
          <el-button type="primary" icon="el-icon-download" size="small" @click="getExportExcel" :disabled="disabled">导出
          </el-button>
        </el-form-item>
      </el-form>

      <!-- 表格 -->
      <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
        element-loading-background="rgba(0,0,0,0.8)" :data="dataList" stripe border show-overflow-tooltip>
        <el-table-column type="index" width="40px"></el-table-column>
        <el-table-column prop="description" label="问题简述" show-overflow-tooltip></el-table-column>
        <el-table-column prop="notes" label="问题详述" show-overflow-tooltip></el-table-column>
        <el-table-column prop="ufcresult" label="处理意见" show-overflow-tooltip></el-table-column>
        <el-table-column prop="ufccontent" label="问题类型" width="100px"></el-table-column>
        <el-table-column prop="factoryname" label="分厂" width="120px"></el-table-column>

        <el-table-column label="问题责任人信息" width="260px">
          <template scope="scope">
            <div v-if="scope.row.responseuserimages">
              <el-image style="width:48px;height: 48px;" :src="scope.row.responseuserimages"
                :preview-src-list="[scope.row.responseuserimages]">
              </el-image>
            </div>
            <div v-else>
              <el-image style="width:48px;height: 48px;" :src="'../images/person_blue.png'">
              </el-image>
            </div>
            <p style="margin:0;">责任人: {{scope.row.responsibleperson}}</p>
            <p style="margin:0;">责任单位: {{scope.row.workcentername}}</p>
            <p style="margin:0;">要求完成时间: {{scope.row.ufcchulidate.replace('T',' ')}}</p>
            <p style="margin:0;">问题完成时间:
              <span v-if="scope.row.ufcwanchengdate">
                {{scope.row.ufcwanchengdate.replace('T',' ')}}
              </span>
            </p>
          </template>
        </el-table-column>

        <el-table-column label="问题提出人信息" width="220px">
          <template scope="scope">
            <div v-if="scope.row.createuserimages">
              <el-image style="width:48px;height: 48px;" :src="scope.row.createuserimages"
                :preview-src-list="[scope.row.createuserimages]">
              </el-image>
            </div>
            <div v-else>
              <el-image style="width:48px;height: 48px;" :src="'../images/person_blue.png'">
              </el-image>
            </div>
            <p style="margin:0;">提出人: {{scope.row.createperson}}</p>
            <p style="margin:0;">提出单位: {{scope.row.createworkcenter}}</p>
            <p style="margin:0;">提出时间: {{scope.row.ufccreatedate.replace('T',' ')}}</p>
            <p style="margin:0;">关闭时间:
              <span v-if="scope.row.ufcguanbidate">
                {{scope.row.ufcguanbidate.replace('T',' ')}}
              </span>
            </p>
          </template>
        </el-table-column>

        <el-table-column prop="status" label="状态" width="80px">
          <template scope="scope">
            <div v-if="scope.row.status === '已关闭'">
              <el-tag type="info">已关闭</el-tag>
            </div>
            <div v-else-if="scope.row.status === '未处理'">
              <el-tag type="danger">未处理</el-tag>
            </div>
            <div v-else-if="scope.row.status === '处理中'">
              <el-tag type="warning">处理中</el-tag>
            </div>
            <div v-else-if="scope.row.status === '处理完'">
              <el-tag type="success">处理完</el-tag>
            </div>
          </template>
        </el-table-column>

        <el-table-column prop="priority" label="需求程度" width="100px"></el-table-column>
        <el-table-column prop="delayday" label="超期天数" width="100px">
          <template scope="scope">
            <p v-if="scope.row.delayday > 0" style="color:red;font-weight: bold;">
              <i class="el-icon-date"></i> {{scope.row.delayday}}天
            </p>
            <p v-else>
              <i class="el-icon-date"></i> 0天
            </p>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :current-page="queryInfo.currentPage" :page-sizes="[10,20,50]" :page-size="queryInfo.pageSize"
        layout="prev,pager,next,jumper,sizes,total" :total="total">
      </el-pagination>

      <!-- 回到顶部 -->
      <el-backtop></el-backtop>
    </div>
  </div>

  <script type="module">
    import { getParams, exportExcelData } from '../Scripts/hooks/useCommonMethod.js'
    import { getFactory, getWorkcenterList, getUserInfo } from '../Scripts/hooks/fetchAPI.js'
    import { prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth } from '../Scripts/hooks/useDateShortCut.js'
    import Vue2ReportHeader from '../Scripts/components/Vue2ReportHeader.js'
    const app = new Vue({
      el: '#app',
      components: { Vue2ReportHeader },
      data: {
        loading: false,
        loadingText: '数据加载中...',
        total: 0,
        employeeid: '',
        queryInfo: {
          factoryid: '',//分厂
          creatPerson: '',// 提出人
          createDate: '',// 提出日期
          status: '',// 状态
          createWorkcenterid: '',// 提出工区
          resWorkcenterid: '',// 责任工区
          responsePerson: '',// 责任人
          containername: '',// 流水卡号
          currentPage: 1,//当前页
          pageSize: 10//每页显示条数
        },
        dataList: [],
        disabled: false, //按钮是否禁用
        ddlFactoryDisabled: false,
        factoryList: [],
        workcenterList: [],//所有工区
        // 表单验证
        rules: { factoryid: [{ required: true, message: '分厂不能为空', trigger: 'change' }] },
        pickerOptions: { shortcuts: [prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth] }
      },
      methods: {
        //查询数据
        async getData() {
          this.$refs['queryInfoRef'].validate(async (valid) => {
            if (!valid) {
              return this.$message.error('必填项不能为空');
            } else {
              this.loading = true;
              this.loadingText = '数据加载中...';
              const { data: { data, meta, total } } = await axios.post('../handler/report/ProblemReport.ashx?action=getData', {
                type: 'getData',
                ...this.queryInfo
              })
              this.loading = false;
              if (meta.status === 500) { return this.$message.error(meta.msg); }
              this.dataList = data;
              this.total = total;
            }
          })
        },
        // 导出excel
        async getExportExcel() {
          this.$refs['queryInfoRef'].validate(async (valid) => {
            if (!valid) {
              return this.$message.error('必填项不能为空');
            } else {
              const config = {
                url: '../handler/report/ProblemReport.ashx?action=exportExcel',
                data: { type: 'exportExcel', ...this.queryInfo }
              }
              exportExcelData(config, this);
            }
          })
        },
        //监听 页码值 改变的事件
        handleCurrentChange(newPage) {
          this.queryInfo.currentPage = newPage;
          this.getData();
        },
        //监听 pagesize 改变的事件
        handleSizeChange(newSize) {
          this.queryInfo.pageSize = newSize;
          this.getData();
        },
        //绑定 【查询区】 对话框中的工区下拉框
        async bindSearchWorkcenter(factoryid) {
          this.queryInfo.createWorkcenterid = null;
          this.queryInfo.resWorkcenterid = null;
          if (factoryid) {
            this.workcenterList = await getWorkcenterList({ factoryid });
          }
        }
      },
      async mounted() {
        this.factoryList = await getFactory();
        const userInfo = await getUserInfo({ employeeid: getParams("uid") });
        const { factoryid } = this.factoryList.some(i => i.factoryid === userInfo.factoryid) ? userInfo : this.factoryList[0];
        this.queryInfo.factoryid = factoryid;
        this.workcenterList = await getWorkcenterList({ factoryid });
      },
      watch: { queryInfo: { handler() { this.queryInfo.currentPage = 1 }, deep: true } }
    })
  </script>
</body>

</html>